﻿#include "EquationSolver.h"
using namespace std;


class F1 : public Function
{
public:
    double operator()(double x)
    {
        return 1 / x - tan(x);
    }
};

class F2 : public Function
{
public:
    double operator()(double x)
    {
        return 1 / x - pow(2, x);
    }
};

class F3 : public Function
{
public:
    double operator()(double x)
    {
        return pow(2, -x) + exp(x) + 2 * cos(x) - 6;
    }
};

class F4 : public Function
{
public:
    double operator()(double x)
    {
        return  (pow(x, 3) + 4 * pow(x, 2) + 3 * x + 5) / (2 * pow(x, 3) - 9 * pow(x, 2) + 18 * x - 2);
    }
};

int main(int argc, char* argv[]) {
    cout << "------------------TestB---------------:" << endl;
    F1 func1;
    F2 func2;
    F3 func3;
    F4 func4;
    BisectionSolver Bisec1(0, M_PI / 2, eps, 100, func1);
    BisectionSolver Bisec2(0, 1, eps, 100, func2);
    BisectionSolver Bisec3(1, 3, eps, 100, func3);
    BisectionSolver Bisec4(0, 4, eps, 100, func4);
    cout << ("task1:\t1/x-tan(x)                                   ");
    cout << "root = " << Bisec1.solve() << "   " << "f(root) = " << func1(Bisec1.solve()) << endl;
    cout << ("task2:\t1/x-2^x                                      ");
    cout << "root = " << Bisec2.solve() << "   " << "f(root) = " << func2(Bisec2.solve()) << endl;
    cout << ("task3:\t2^-x+e^x+2cosx-6                             ");
    cout << "root = " << Bisec3.solve() << "   " << "f(root) = " << func3(Bisec3.solve()) << endl;
    cout << ("task4:\t(x^3+4x^2+3x+5)/(2x^3-9x^2+18x-2)            ");
    cout << "root = " << Bisec4.solve() << "   " << "f(root) = " << func4(Bisec4.solve()) << endl;
    return 0;
}